#include "config.h"

#include <string.h>
#include <WinSock2.h>
#include <Ws2tcpip.h>
#include <stdio.h>
#include "connections.h"

static int serverStatus; // variabel for server active(1) och not active(0)

serverValueT loadServerValues(void){
	serverValueT serverValue;
	char *lineA, *lineB, *lineC, *lineD, *lineE;
	FILE *configFile;

	
	configFile = fopen("config.txt", "r");

	lineA = malloc(80 * sizeof(char));
	fgets(lineA, 80, configFile);
	serverValue.adminPassword = strtok(lineA, "\n");
	
	lineB = malloc(80 * sizeof(char));
	fgets(lineB, 80, configFile);
	serverValue.httpPort = strtok(lineB, "\n");

	lineC = malloc(80 * sizeof(char));
	fgets(lineC, 80, configFile);
	serverValue.telnetPort = strtok(lineC, "\n");

	lineD = malloc(80 * sizeof(char));
	fgets(lineD, 80, configFile);
	serverValue.searchPath = strtok(lineD, "\n");

	lineE = malloc(80 * sizeof(char));
	fgets(lineE, 80, configFile);
	serverValue.logFileSearchPath = strtok(lineE, "\n");
	
	fclose(configFile);
	
	return(serverValue);
}

int isServerActive(void){
	return(serverStatus);
}

void startServer(void){
	if (!serverStatus){
		serverStatus = 1; // Set server to active.
		startHTTPThread();
	}
}

void stopServer(void){
	serverStatus = 0;
}
